<template>
  <div class="wrap">
    <!-- 轮播图 -->
    <el-carousel trigger="click" height="150px">
      <el-carousel-item
        v-for="item in banner"
        :key="item.id"
        class="banner-img"
      >
        <img :src="`https://ss.lanqb.com/${item.picture}`" alt="" />
      </el-carousel-item>
    </el-carousel>
    <!-- 头部主题 -->
    <ul>
      <li>
        <div>
          <img
            src="https://assets-cdn.lanqb.com/imgv3_m/images-icon/h-submenu01.png"
          />
        </div>
        <p>免费教程</p>
      </li>
      <li>
        <div>
          <img
            src="https://assets-cdn.lanqb.com/imgv3_m/images-icon/h-submenu04.png"
          />
        </div>
        <p>教程兑换</p>
      </li>
      <li @click="toDachu">
        <div>
          <img
            src="https://assets-cdn.lanqb.com/imgv3_m/images-icon/h-submenu15.png"
          />
        </div>
        <p>大触来了</p>
      </li>
      <li>
        <div>
          <img
            src="https://assets-cdn.lanqb.com/imgv3_m/images-icon/h-submenu21.png"
          />
        </div>
        <p>品牌实况</p>
      </li>
    </ul>
    <!-- 查看详情 -->
    <div class="look-video">
      <p>大触直播</p>
      <p @click="toDachu">查看更多</p>
    </div>
    <!-- 大触直播 -->
    <div class="play">
      <div class="playVideo" v-for="item in touchCourse" :key="item.id">
        <div class="author">
          <img :src="`https://ss.lanqb.com/${item.profile.avatar}`" alt="" />
          <p>{{ item.profile.nickname }}</p>
        </div>

        <h4>{{ item.title }}</h4>

        <div class="video-pic">
          <img :src="`https://ss.lanqb.com/${item.cover}`" alt="" />
        </div>

        <div class="video-text">
          <p>时间: {{ item.begin_at }}</p>
          <p>{{ item.statistic.purchases }} 人感兴趣</p>
        </div>
      </div>
    </div>
    <!-- 查看详情-->
    <div class="look-video">
      <p>热门教程</p>
      <p>查看更多</p>
    </div>
    <!-- 热门教程 -->
    <div class="hot">
      <div class="hot_content" v-for="item in hotCourse" :key="item.id">
        <div class="hot_img">
          <img :src="'https://ss.lanqb.com/' + item.posters.mobile" />
          <p>{{ item.title }}</p>
        </div>
      </div>
    </div>
    <!-- 查看详情 -->
    <div class="look-video">
      <p>图文教程</p>
      <p>查看更多</p>
    </div>
    <!-- 图文教程 -->
    <div class="pic-text">
      <div class="pic-text-content" v-for="item in picCourse" :key="item.id">
        <div class="content-img">
          <img :src="`https://ss.lanqb.com/${item.imgCover}`" alt="" />
        </div>
        <div class="content-title">
          <h3>{{ item.title }}</h3>
          <p>老师:{{ item.user_profile.nickname }}</p>
        </div>
      </div>
    </div>
    <!-- 查看详情 -->
    <div class="look-video">
      <p>推荐咨询</p>
      <p>查看更多</p>
    </div>
    <!-- 推荐咨询 -->
    <div class="pic-text">
      <div
        class="pic-text-content"
        v-for="item in recommendCourse"
        :key="item.id"
      >
        <div class="content-img">
          <img :src="`https://ss.lanqb.com/${item.imgCover}`" alt="" />
          <p>{{ item.category.category_name }}</p>
        </div>
        <div class="content-title">
          <h3>{{ item.title }}</h3>
          <p>
            {{
              item.created_at
                .slice(0, 10)
                .replace("-", "年")
                .replace("-", "月")
            }}日
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "IndexVue",
  data() {
    return {
      banner: [], // 轮播图
      touchCourse: [], // 大触数据
      hotCourse: [], // 热门教程
      picCourse: [], //图文教程
      recommendCourse: [], // 推荐咨询
    };
  },
  methods: {
    toDachu() {
      this.$router.push("/dachu");
    },
  },

  // computed:{
  //   change(){
  //     var str = this.item.created_at.slice(0,11);
  //     str = str.split('');
  //     str.splice(4,1,'年');
  //     str.splice(7,1,'月');
  //     str.push('日');
  //     str = str.join();
  //     return str;
  //   }
  // },
  created() {
    /* 轮播 */
    fetch(
      "https://m.lanqb.com/api/home/banner?type=m&local_code=10&limit=6&order=weight"
    )
      .then((res) => res.json())
      .then((data) => {
        this.banner = data.data;
        console.log(this.banner);
      });
    /* 大触直播 */
    fetch(
      "https://m.lanqb.com/api/daniu?link=paging&live=3&is_live=1&limit=3&page=1"
    )
      .then((res) => res.json())
      .then((data) => {
        this.touchCourse = data.live.slice(0, 3);
        console.log(this.touchCourse);
      });
    /* 热门教程 */
    fetch("https://m.lanqb.com/api/home/series")
      .then((res) => res.json())
      .then((data) => {
        this.hotCourse = data.slice(0, 4);
        console.log(this.hotCourse);
      });
    /* 图文教程 */
    fetch("https://m.lanqb.com/api/home/graphic-tutorials")
      .then((res) => res.json())
      .then((data) => {
        this.picCourse = data.slice(0, 3);
        console.log(this.picCourse);
      });
    /* 推荐咨询 */
    fetch("https://m.lanqb.com/api/home/news")
      .then((res) => res.json())
      .then((data) => {
        this.recommendCourse = data;
        console.log(this.recommendCourse);
      });
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
.wrap {
  height: calc(100vh - 48px - 44px - 60px);
  overflow-y: scroll;
  .banner-img {
    img {
      width: 100%;
    }
  }
  ul {
    height: 101px;
    // background-color: rgb(77, 181, 218);
    display: flex;
    justify-content: space-around;
    li {
      padding: 16px 0;
      div {
        img {
          width: 48px;
          height: 48px;
          border-radius: 50%;
        }
      }
      p {
        font-size: 12px;
        margin-top: 5px;
        text-align: center;
      }
    }
  }
  /* 查看详情 */
  .look-video {
    padding: 0 12px;
    height: 38px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .look-video p:nth-child(2) {
    color: #a4a4a4;
  }
  /* 大触直播 */
  .play {
    display: flex;
    width: 95%;
    flex-wrap: wrap;
    padding: 10px;
    .playVideo {
      width: 170px;
      margin: 5px 3px;
      border-radius: 3px;
      box-shadow: 2px 2px 16px rgb(198, 193, 193);
      padding: 10px;
      .author {
        display: flex;
        align-items: center;
        margin: 10px 0;
        img {
          width: 19px;
          height: 19px;
          border-radius: 50%;
        }
        p {
          color: #000000;
          font-size: 12px;
          margin-left: 5px;
        }
      }
      h4 {
        color: #222;
        font-weight: 700;
        cursor: pointer;
        font-size: 14px;
        margin: 5px 0;
        font-weight: bolder;
      }
      .video-pic {
        img {
          width: 100%;
          border-radius: 10px;
        }
      }
      .video-text {
        p {
          color: #a4a4a4;
          font-size: 12px;
        }
      }
    }
  }
  .playVideo:nth-child(1) {
    width: 368px;
  }
  .playVideo:nth-child(1) > .video-text {
    display: flex;
    justify-content: space-between;
    margin: 5px 0;
  }
  /* 热门教程 */
  .hot {
    width: 95%;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .hot_content {
      width: 48%;
      .hot_img {
        width: 50%;
        img {
          width: 188px;
          height: auto;
        }
        p {
          width: 188px;
          font-size: 14px;
          margin: 10px 0;
        }
      }
    }
  }
  /* 图文教程 */
  .pic-text {
    width: 95%;
    padding: 10px;
    .pic-text-content {
      display: flex;
      padding: 10px 0;
      border-bottom: 1px solid #eee;
      .content-img {
        position: relative;

        img {
          width: 127px;
          height: auto;
          border-radius: 5px;
        }
        p {
          background: orange;
          height: 18px;
          line-height: 18px;
          color: white;
          border-radius: 0px 0px 5px 5px;
          font-size: 12px;
          position: absolute;
          top: 0px;
          left: 5px;
        }
      }
      .content-title {
        margin-left: 10px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        h3 {
          font-size: 18px;
          color: #222;
          font-weight: 800;
          text-align: justify;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          line-height: 20px;
        }
        p {
          color: #a4a4a4;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
